import  {parse} from 'qs'
export default {
    namespace:'text',
    state:{
		title:'继承的老标题',
		tableList:[]
    },
    //同步方法，存值
    reducers:{
        changeTitle(state,action){
			/* const{title} = yield select(state=>state.text) */
            return({
				title:action.payload.title  
            })
        }
    },
    //异步方法
    effects:{
        *init({},{call,put,select}){
           
            let newTestMessage='新值'
            yield put({//action对象
                type:'save',
                payload:{//pageName：3也行
                    testMessage:newTestMessage
                }
            })
		},
		*dchangetitle({totalTitle},{call,put,select}){//action对象
			/*   const{testMessage} = yield select(state=>state.test) */
			  yield put({
				  type:'changeTitle',
				  payload:{
					  title:totalTitle
				  }
			  })
		  },
		/* *echangetitle({},{call,put,select}){
            let newTestMessage='更新后的新标题'
            yield put({
                type:'changeTitle',
                payload:{
                    title:newTestMessage
                }
            })
        } */
    },
    subscriptions:{
        setup({dispatch,history}){
            return history.listen(({pathname,search})=>{
                const query = parse(search.split('?')[1]);
                if(pathname === '/text'){dispatch({type:'init'})}
            })
        }
    },
}